// todo 优化-时钟案例的web服务器
const fs = require('fs')
const path = require('path')
const http = require('http')
const server = http.createServer()
server.on('request', (req, res) => {
    let{ url } = req
  if (url==='/') {
    url = '/index.html'
  }
        const filePath = path.join(__dirname, 'clock',url)
        fs.readFile(filePath, 'utf-8', (err, data) => {
            if (err) {
                return console.log(`读取失败${err.message}`);
            }
           
            res.end(data)
        })
  
})

server.listen(3000, () => {
    console.log('本机开启服务器');
})